<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Upload</title>
</head>
<body>
    <h1>File Upload</h1>
    <form id="uploadForm" enctype="multipart/form-data">
        <label for="teamName">Team Name:</label>
        <input type="text" id="teamName" name="team_name" required><br><br>
        <label for="phoneNumber">Phone Number:</label>
        <input type="text" id="phoneNumber" name="phone_number" required><br><br>
        <input type="file" id="fileInput" name="file" accept=".pdf" required><br><br>
        <button type="submit">Upload File</button>
    </form>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', function(event) {
            event.preventDefault();

            var formData = new FormData();
            formData.append('team_name', document.getElementById('teamName').value);
            formData.append('phone_number', document.getElementById('phoneNumber').value);
            formData.append('file', document.getElementById('fileInput').files[0]);

            fetch('/upload', {
                method: 'POST',
                body: formData
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.json();
            })
            .then(data => {
                console.log(data);
                alert('File uploaded successfully!');
                // 清除表单
                document.getElementById('teamName').value = '';
                document.getElementById('phoneNumber').value = '';
                document.getElementById('fileInput').value = '';
            })
            .catch(error => {
                console.error('There was a problem with the upload:', error);
                alert('There was a problem with the upload. Please try again.');
            });
        });
    </script>
</body>
</html>
